package util;
import java.util.Properties;   
import javax.naming.InitialContext;   
import javax.naming.NamingException;   
  
public class JNDIUtil   
{   
  
    private static InitialContext ctx = null;   
  
    public static Object lookup(String jndiBinding)   
    {   
  
        if (ctx == null)   
        {   
  
            //下面是JBOSS的配置，如果用其它EJB容器，得换了下面的某些信息   
            Properties props = new Properties();   
            props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
//            props.setProperty("java.naming.provider.url", "10.10.67.80:1199");
            
            props.setProperty("java.naming.provider.url", "localhost:1199");   
//			  props.setProperty("java.naming.provider.url", "10.10.41.192:1099");
//            props.setProperty("java.naming.provider.url", "10.10.38.133:9172");
//            props.setProperty("java.naming.provider.url", "10.10.67.80:1199");
//            props.setProperty("java.naming.provider.url", "10.10.43.113:1099,10.10.43.114:1099");
//            props.setProperty("java.naming.provider.url", "10.10.43.52:1099");
//            props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");   
               
			//System.out.println("注意EJB服务 地址：" + props.getProperty("java.naming.provider.url"));
           try  
            {   
                ctx = new InitialContext(props);
            }   
            catch (NamingException ex)   
            {   
            	ex.printStackTrace();
                //System.out.println("InitialContext Exception: may be you used wrong property name or value!");   
            }   
        }   
  
        try  
        {   
            return ctx.lookup(jndiBinding);   
        }   
        catch (NamingException ex)   
        {   
        	ex.printStackTrace();
            System.out.println("JNDI look up Exception: jndi name '" + jndiBinding + "' not found!");   
        }   
  
        return null;   
    }   
}  
